package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.query.UserCouponQuery;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.IUserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户领取优惠券的记录，是真正使用的优惠券信息 前端控制器
 * </p>
 *
 * @author xzh
 * @since 2024-03-20
 */
@EnableAspectJAutoProxy(exposeProxy = true)//暴露代理对象
@RestController
@RequestMapping("/user-coupons")
@Api(tags = "客户端优惠券相关接口")
@RequiredArgsConstructor
public class UserCouponController {

    private final IUserCouponService userCouponService;

    /**
     * 用户领取优惠券
     * @param id
     */
    @PostMapping("/{id}/receive")
    @ApiOperation(value = "用户领取优惠券")
    public void saveUserCouponById(@PathVariable(value = "id") Long id){
        userCouponService.saveUserCouponById(id);
    }

    /**
     * 用户兑换兑换码
     * @param code
     */
    @PostMapping("/{code}/exchange")
    @ApiOperation(value = "用户兑换兑换码")
    public void saveUserExchangeCodeById(@PathVariable(value = "code") String code){
        userCouponService.saveUserExchangeCodeById(code);
    }

    /**
     * 分页查询我的优惠券
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询我的优惠券")
    public PageDTO<CouponVO> queryUserCouponPage(UserCouponQuery query){
        return userCouponService.queryUserCouponPage(query);
    }

}
